package net.sky.oa.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 岗位表
 * SysPost. @author hond
 */
@Entity
@Table(name = "SYS_POST")//岗位表
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SysPost implements java.io.Serializable {

	private static final long serialVersionUID = 5673991033245515351L;
	
	// Fields

	protected Long id;
	private String name;    //岗位名称
	private String mark;    //岗位标识
	//private SysDept dept;   //所属部门
	private Integer rank;      //岗位级别
	private String function;//岗位职能
	private Integer status;    //状态：1使用2禁用
	private Date createtime;//创建时间
	private SysEmployee user; //创建人
//	private Short parentId; //上级岗位
	/*private SysPost parent;
	private Set<SysPost> children = new HashSet<SysPost>(0);*/
	
	
	
	private String oldname;        //记录原名称

	// Constructors

	/** default constructor */
	public SysPost() {
	}
	
	/**
	 * @param id
	 * @param name
	 */
	public SysPost(Long id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	@Id
    @Column(name = "ID", unique = true, nullable = false)
	@SequenceGenerator(name="SQ_SYSPOST_ID",sequenceName="SQ_SYSPOST_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SQ_SYSPOST_ID")
	public Long getId() {
        return id;
    }

    public void setId(Long id){
    	this.id = id;
    }

	/** minimal constructor */
	public SysPost(Long id) {
		this.id = id;
	}
 
	@Column(name = "NAME", length = 20)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "MARK", length = 20)
	public String getMark() {
		return this.mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

	/*@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "DEPT_ID")
	public SysDept getDept() {
		return this.dept;
	}

	public void setDept(SysDept dept) {
		this.dept = dept;
	}*/

	@Column(name = "RANK", precision = 2, scale = 0)
	public Integer getRank() {
		return this.rank;
	}

	public void setRank(Integer rank) {
		this.rank = rank;
	}

	@Column(name = "FUNCTION", length = 100)
	public String getFunction() {
		return this.function;
	}

	public void setFunction(String function) {
		this.function = function;
	}
	
	@Column(name = "STATUS", length = 1)
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATETIME", length = 7)
	public Date getCreatetime() {
		return this.createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	
	/*@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID")
    public SysPost getParent() {
        return parent;
    }

    public void setParent(SysPost parent) {
        this.parent = parent;
    }
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
    @OrderBy("rank asc, id desc")
    public Set<SysPost> getChildren() {
        return children;
    }

    *//** * @param children Set. *//*
    public void setChildren(Set<SysPost> children) {
        this.children = children;
    }*/
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "USER_ID")
	public SysEmployee getUser() {
		return this.user;
	}

	public void setUser(SysEmployee user) {
		this.user = user;
	}
	
	@Transient
	public String getOldname() {
		return oldname;
	}

	public void setOldname(String oldname) {
		this.oldname = oldname;
	}
}